﻿
Imports xhtmlctrl

Public Class windowUnload
    Public Const parameterName As String = "e"

    Public Shared Sub invoke(ByVal inlineScript As inlineScript, ByVal action As String)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        inlineScript.addscript(network.http.contentType.textjavascript, "windowUnloadAction", invoke(action))
    End Sub

    Public Shared Function invoke(ByVal action As String, Optional ByRef actionTarget As String = Nothing)
        actionTarget += "window.onbeforeunload=function(" + parameterName + "){" + action + "}"
        Return actionTarget
    End Function
End Class

Public Class oneparaAlert
    Public Const functionName As String = "opalt"

    Public Shared Sub invoke(ByVal inlineScript As inlineScript _
                             , ByVal para As String _
                             , ByVal message As String _
                             , ByRef actionTarget As String)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        assert(Not para Is Nothing, "para is nothing.")
        assert(Not message Is Nothing, "message is nothing.")
        inlineScript.addscript(network.http.contentType.textjavascript, "oneparaAlert" _
                               , "function " + functionName _
                               + "(p,m){p.returnValue=m;}")
        actionTarget += functionName + "(" + para + "," + message + ")"
    End Sub
End Class

Public Class prompt
    Public Const functionName As String = "prm"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        inlineScript.addscript("prompt", "function " + functionName + "(t,v){return prompt(t,v);}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, _
                                  Optional ByVal title As String = Nothing, _
                                  Optional ByVal value As String = Nothing, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + ifoper(isemptystring(title), "''", title) + "," + _
                        ifoper(isemptystring(value), "''", value) + ")"
        Return actionTarget
    End Function
End Class

Public Class prompt2
    Public Const functionName As String = "prm2"
    Public Const inputBoxResult As String = "r"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        't = title, v = value, s = succAction, f = failedAction
        inlineScript.addscript("prompt2", "function " + functionName + "(t,v,s,f){" + _
                               var.invoke(inputBoxResult, prompt.invoke(inlineScript, "t", "v")) + ";" + _
                               ifelse.invoke(notnull.invoke(inlineScript, inputBoxResult), _
                                             "s(" + inputBoxResult + ")", _
                                             "f(" + inputBoxResult + ")") + "}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, _
                                  ByVal succAction As String, _
                                  Optional ByVal failedAction As String = Nothing, _
                                  Optional ByVal title As String = Nothing, _
                                  Optional ByVal value As String = Nothing, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + ifoper(isemptystring(title), "''", title) + "," + _
                                             ifoper(isemptystring(value), "''", value) + "," + _
                                             ifoper(isemptystring(succAction), _
                                                    "function(" + inputBoxResult + "){}", _
                                                    succAction) + "," + _
                                             ifoper(isemptystring(failedAction), _
                                                    "function(" + inputBoxResult + "){}", _
                                                    failedAction) + ")"
        Return actionTarget
    End Function
End Class

Public Class confirm
    Public Const functionName As String = "cfm"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        inlineScript.addscript("confirm", "function " + functionName + "(s){return confirm(s);}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal message As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + message + ")"
        Return actionTarget
    End Function
End Class

Public Class confirm2
    Public Const functionName As String = "cfm2"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        'm = message, s = succAction, f = failedAction
        inlineScript.addscript("confirm2", "function " + functionName + "(m,s,f){" + _
                               ifelse.invoke(confirm.invoke(inlineScript, "m"), "s()", "f()") + "}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, _
                                  ByVal message As String, _
                                  ByVal succAction As String, _
                                  Optional ByVal failedAction As String = Nothing, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + ifoper(isemptystring(message), "''", message) + "," + _
                                             ifoper(isemptystring(succAction), "function(){}", succAction) + "," + _
                                             ifoper(isemptystring(failedAction), "function(){}", failedAction) + ")"
        Return actionTarget
    End Function
End Class